{extend name="public/original" /}
{block name="title"}SKU设置{/block}
{block name="content"}
<div class="layui-form" lay-filter="layuiadmin-form-admin" id="layuiadmin-form-admin" style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
      <label class="layui-form-label">库存</label>
      <div class="layui-input-inline">
        <input type="text" name="stocks" lay-verType="tips" lay-verify="required" autocomplete="off" class="layui-input stockIpt" value="{$sku.stocks}">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">价格</label>
      <div class="layui-input-inline">
        <input type="text" name="price" lay-verType="tips" lay-verify="required" autocomplete="off" class="layui-input priceIpt" value="{$sku.price}">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">市场价</label>
      <div class="layui-input-inline">
        <input type="text" name="market_price" lay-verType="tips" lay-verify="required" autocomplete="off" class="layui-input marketIpt" value="{$sku.market_price}">
      </div>
    </div>
    <div class="layui-form-item layui-hide">
      <input type="hidden" name="sku_id" value="{$sku.id}">
      <input type="button" lay-submit lay-filter="sku-set" id="sku-set" value="确认">
    </div>
  </div>
{/block}
{block name="footjs"}
<script type="text/javascript">
layui.use(['form'], function(){
  var form = layui.form
  $('.stockIpt').on('blur', function(){
    var _this = $(this)
    var _thisVal = _this.val().trim()
    var idx = _this.parents('tr').index()

    if($.isNumeric(_thisVal)){
      _this.val(parseInt(_thisVal));
    }else{
      _this.val(0);
    }

    if(typeof skusVal[idx] == 'undefined'){
      skusVal[idx] = {}
    }
    skusVal[idx].stock = _this.val()
    
    $('input[name=skus_val]').val(JSON.stringify(skusVal))
  })

  $('.marketIpt').on('blur', function(){
    var _this = $(this)
    var _thisVal = _this.val().trim()
    var idx = _this.parents('tr').index()

    if($.isNumeric(_thisVal)){
      _this.val(parseFloat(_thisVal).toFixed(2));
    }else{
      _this.val(0);
    }

    if(typeof skusVal[idx] == 'undefined'){
      skusVal[idx] = {}
    }
    skusVal[idx].marketPrice = _this.val()
    
    $('input[name=skus_val]').val(JSON.stringify(skusVal))
  })
  
  $('.priceIpt').on('blur', function(){
    var _this = $(this)
    var _thisVal = _this.val().trim()
    var idx = _this.parents('tr').index()

    if($.isNumeric(_thisVal)){
      _this.val(parseFloat(_thisVal).toFixed(2));
    }else{
      _this.val(0);
    }

    if(typeof skusVal[idx] == 'undefined'){
      skusVal[idx] = {}
    }
    skusVal[idx].price = _this.val()
    
    $('input[name=skus_val]').val(JSON.stringify(skusVal))
  })
});
</script>
{/block}